package com.dou361.ijkplayer.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.ImageView;

import com.dou361.ijkplayer.R;

import java.util.Random;

/**
 * 本类为自定义的点赞图标
 */

public class HeartImageView extends ImageView {
  private int l,t,r,b;
  private Random random;
  private Paint mBitPaint;
  private Bitmap bmp;
  private Bitmap mBitmap;

  public HeartImageView(Context context) {
    this(context,null);
  }

  public HeartImageView(Context context, AttributeSet attrs) {
    this(context, attrs,0);
  }

  public HeartImageView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    //setImageResource(R.drawable.liveselicon);
    random = new Random();
    initPaint();
    initBitmap();
    //setColorFilter(Color.parseColor("#f23a58"));
  }

  @TargetApi(Build.VERSION_CODES.KITKAT)
  private void initBitmap() {
    Resources resources = getResources();

    bmp = BitmapFactory.decodeResource(resources, R.drawable.liveselicon);

  }

  public void setLayout(int l,int t,int r,int b){
    setL(l);
    setT(t);
    setR(r);
    setB(b);
  }
  private void initPaint() {
    mBitPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBitPaint.setFilterBitmap(true);
    mBitPaint.setDither(true);
  }

  public int getL() {
    return l;
  }

  public void setL(int l) {
    this.l = l;
  }

  public int getT() {
    return t;
  }

  public void setT(int t) {
    this.t = t;
  }

  public int getR() {
    return r;
  }

  public void setR(int r) {
    this.r = r;
  }

  public int getB() {
    return b;
  }

  public void setB(int b) {
    this.b = b;
  }

  @Override
  protected void onDraw(Canvas canvas) {

    super.onDraw(canvas);
    //canvas.rotate(random.nextInt(120)+30);

    int x = bmp.getWidth();
    int y = bmp.getHeight();
    y= (int) (y*1.5);
    canvas.translate(x, y);
    canvas.rotate(random.nextInt(20)+350);
    //canvas.translate(-y, x-y);
    canvas.drawBitmap(bmp , 0, 0,mBitPaint);

  }
//  @Override
//  protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
//  {
//    int height = View.MeasureSpec.getSize(heightMeasureSpec);
//    int width = View.MeasureSpec.getSize(widthMeasureSpec);
//    //setMeasuredDimension(50,50);  //这里面是原始的大小，需要重新计算可以修改本行
//    //dosomething
//  }




}
